package org.ichow.core
{
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.Event;
	import org.ichow.debug.Debug;
	
	/**
	 * ...
	 * @author Minos
	 */
	public class BaseMain extends Sprite
	{
		protected var config : Object;
		protected var def_config : Object = {};
		protected var projectName : String = "None";
		
		public function BaseMain( n : String = "" )
		{
			
			projectName = n;
			if ( stage )
				init();
			else
				addEventListener( Event.ADDED_TO_STAGE , init );
		}
		
		protected function init( e : Event = null ) : void
		{
			removeEventListener( Event.ADDED_TO_STAGE , init );
			
			// entry point
			stage.scaleMode = StageScaleMode.NO_SCALE;
			stage.align = StageAlign.TOP_LEFT;
			Debug.monitor( stage );
			
			addEventListener( Event.REMOVED_FROM_STAGE , onRemove );
		}
		
		protected function onRemove( e : Event = null ) : void
		{
			removeEventListener( Event.REMOVED_FROM_STAGE , onRemove );
		
		}
		
		public function setConfig( data : Object = null ) : void
		{
			config = data;
			Debug.trace( "setConfig: " , Debug.LEVEL_DEBUG );
			Debug.traceObj( data , 5 , Debug.LEVEL_DEBUG );
		}
		
		public function getValueByKey( v : String ) : Object
		{
			if ( config && config[ v ] )
				return config[ v ];
			else
				return def_config[ v ];
		}
	
	}

}